package top.ahwyy.controller.Action;

import java.io.UnsupportedEncodingException;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.apache.struts2.interceptor.ServletRequestAware;
import org.apache.struts2.interceptor.ServletResponseAware;

import top.ahwyy.controller.impl.userImpl;
import top.ahwyy.controller.inter.user;

public class userLoginAction implements ServletResponseAware,ServletRequestAware{
	
	public String un;
	public String pw;
	public String cc;
	
	public String getUn() {
		return un;
	}

	public void setUn(String un) {
		this.un = un;
	}

	public String getPw() {
		return pw;
	}

	public void setPw(String pw) {
		this.pw = pw;
	}

	public String getCc() {
		return cc;
	}

	public void setCc(String cc) {
		this.cc = cc;
	}

	public HttpServletRequest request;
	public HttpServletResponse response;
	
	public String execute(){

		response.setContentType("text/html;charset=utf-8");
		try {
			request.setCharacterEncoding("utf-8");
		} catch (UnsupportedEncodingException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		
		HttpSession session = request.getSession();
		String cc2 = (String) session.getAttribute("checkCode");
		

		if(un == null || pw == null || cc == null ||un.equals("") || pw.equals("") || cc.equals(""))
			return "false";
		
		
		user ui = new userImpl();
		
		boolean flag = ui.userLogin(un, pw, cc, cc2);
		if(flag){
			session.setAttribute("un", un);
			return "success";
		}
		
		return "false";
	}

	@Override
	public void setServletRequest(HttpServletRequest arg0) {
		// TODO Auto-generated method stub
		this.request = arg0;
		
	}

	@Override
	public void setServletResponse(HttpServletResponse arg0) {
		// TODO Auto-generated method stub
		this.response = arg0;
	}
}
